


/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/16/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/  
package com.application.yfappointtask.dao;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.application.yfappointtask.entity.YfAppointTask;
import com.application.yfappointtask.struts.form.YfAppointTaskForm;
import com.manager.commons.CommonUtil;
import com.manager.commons.dao.HibernateGenericDao;
import com.manager.commons.page.PageBean;
 /**
 * 
 * Description:YfAppointTaskDAO<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 02/16/2012 
 * 
 */
public class YfAppointTaskDAO extends HibernateGenericDao<YfAppointTask>
{
    private static final Logger logger = Logger.getLogger(YfAppointTaskDAO.class);

	private YfAppointTask yfAppointTask;

	public YfAppointTask getYfAppointTask() {
		return this.yfAppointTask;
	}

	public void setYfAppointTask(YfAppointTask yfAppointTask) {
		this.yfAppointTask = yfAppointTask;
	}

	public Integer getAllCountYfAppointTask(YfAppointTaskForm yfAppointTaskForm){
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(0) FROM yf_appoint_task t left join usertable u on t.task_belong = u.id left join  usertable w on  t.operateid = w.id  WHERE 1=1 ");
                sql = getStringBuffer(yfAppointTaskForm,sql,args);
              
		return super.getCount(sql.toString(),args.toArray());
	}
        
	public void deleteYfAppointTasks(YfAppointTaskForm yfAppointTaskForm){    	
    		String hql = " delete from YfAppointTask where id = '" + yfAppointTaskForm.getId() + "'";
		Session session = this.getSession();
		try
		{
			session.createQuery(hql).executeUpdate();
		}
		catch(RuntimeException re)
		{
		        logger.error("deleteYfAppointTasks failed");	
			throw re;
		}
		finally
		{
			if (session != null)
			{
				releaseSession(session);
			}
		}
       }

	public List searchYfAppointTask(YfAppointTaskForm yfAppointTaskForm,PageBean pageBean){  
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT t.*,w.rname rname2,u.rname rname FROM yf_appoint_task t left join usertable u on t.task_belong = u.id left join  usertable w on  t.operateid = w.id  WHERE 1=1 ");
		sql = getStringBuffer(yfAppointTaskForm,sql,args);
		  sql.append(" order by t.create_date desc ");
		return getPageInfo(pageBean,sql.toString(),args);
	}

	/**
	 * 查询条件的封装 
	 * @param departmentForm 
	 * @return
	 */
	private StringBuffer getStringBuffer(YfAppointTaskForm yfAppointTaskForm,StringBuffer buf,List args){
		/* 需要加入查询条件时封装
		*/
		
         if(StringUtils.isNotBlank(yfAppointTaskForm.getTaskBelong())){
		    buf.append(" and t.TASK_BELONG like ? ");
			args.add("%" + yfAppointTaskForm.getTaskBelong().trim() + "%");
		}
                				                
		if(null != yfAppointTaskForm.getAuditStatus() && yfAppointTaskForm.getAuditStatus().longValue() != 0){
	     	buf.append(" and t.AUDIT_STATUS = ? ");
			args.add(yfAppointTaskForm.getAuditStatus());
		}
		                
		
        if(StringUtils.isNotBlank(yfAppointTaskForm.getId())){
		    buf.append(" and t.ID = ? ");
		    args.add(yfAppointTaskForm.getId());
		}
		
          if(StringUtils.isNotBlank(yfAppointTaskForm.getOperateid())){
		    buf.append(" and t.OPERATEID = ? ");
			args.add(yfAppointTaskForm.getOperateid().trim());
		}
          if(StringUtils.isBlank(yfAppointTaskForm.getId())){
        		buf = CommonUtil.filterDataZhiPai(buf,args);
  		}
      
        return buf;
	}
	
}
	